﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="Documentation_CRUD_Entities" Codebehind="Entities.aspx.cs" %>

<%@ Register Assembly="Pampa.CRUD" Namespace="Pampa.CRUD.UI.CustomControls" TagPrefix="cc1" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Página sin título</title>
    <link href="../../Css/Layout.css" rel="stylesheet" type="text/css"/>       
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <span class="subtitle">Entities</span>   
        <br />
        <br />
        Every class that is intended to edit with Pampa.Net has to implement the interface Pampa.CRUD.Core.IActiveRecord
        <br />
        <br />
        
<pre class="codeBlock" style="width:auto">
<span class="keyword">public interface</span> <span class="className">IActiveRecord</span>
{
   <span class="keyword">bool</span> IsNew { <span class="keyword">get</span>; }
   <span class="keyword">void</span> Save();
   <span class="keyword">void</span> Delete();
   <span class="keyword">void</span> BeginTransaction();
   <span class="keyword">void</span> RollBackTransaction();
   <span class="keyword">void</span> CommitTransaction();
}
</pre>
 
	Also, there are some static methods that the class migth has to implement:
	<br />
	<br />
	
	
<pre class="codeBlock">
<span class="comment">// For all IActiveRecord classes</span>
<span class="keyword">static</span> <span class="className">MyClass</span> Find(<span class="keyword">object</span> id)
<span class="keyword">static</span> <span class="className">MyClass</span>[] FindAll()

<span class="comment">// Just for classes loaded from an entity control</span>
<span class="keyword">static object</span> ParseId(<span class="keyword">string</span> strId)
     
<span class="comment">// Just for classes that will be listed in a drop down list </span>
<span class="keyword">static</span> <span class="className">MyClass</span>[] FindAll(<span class="keyword">string</span> orderBy)
<span class="keyword">static</span> <span class="className">MyClass</span>[] FindAllByProperty(<span class="keyword">string</span> propertyName, <span class="keyword">object</span> propertyValue, <span class="keyword">string</span> orderBy)
     
<span class="comment">// Just for classes that will be listed in a selector</span>
<span class="keyword">static</span> <span class="className">MyClass</span>[] FindAllByPropertyLike(<span class="keyword">string</span> likeProperty,  <span class="keyword">string</span> likeValue, <span class="keyword">int</span> maxResults)        
<span class="keyword">static</span> <span class="className">MyClass</span>[] FindAllByPropertyLike(<span class="keyword">string</span> likeProperty,  <span class="keyword">string</span> likeValue, <span class="keyword">int</span> maxResults, <span class="keyword">string</span> filterProperty, <span class="keyword">object</span> filterPropertyValue)
</pre>        

		Interface chosen for Entities is inspired in <a href="http://www.castleproject.org/activerecord/index.html">Castle.ActiveRecord</a>.
		Using Castle.ActiveRecord the implementation of IActiveRecord is very easy but of course you could implement persistence methods how do you prefer.

    </div>
    </form>
</body>
</html>
